package com.smart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smart.model.domain.JiansheUnitDO;
import com.smart.model.request.JiansheUnitRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author zhanghong
 */
@Repository
public interface JiansheUnitMapper extends BaseMapper<JiansheUnitDO> {
    JiansheUnitDO selectDOById(Long id);
    List<JiansheUnitDO> selectDOList(JiansheUnitDO jiansheUnit);
    int insertDO(JiansheUnitDO jiansheUnit);
    int batchInsertDO(List<JiansheUnitDO> jiansheUnitDOList);
    int updateDO(JiansheUnitDO jiansheUnit);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from jianshe_unit",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.unitName!=null and param.unitName!=''\">and unit_name like concat('%',#{param.unitName},'%')</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") JiansheUnitRequest param);
    @Select({"<script>",
            "   select * from jianshe_unit",
            "   <where>",
            "       deleted=0",
            "       <if test=\"param.unitName!=null and param.unitName!=''\">and unit_name like concat('%',#{param.unitName},'%')</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<JiansheUnitDO> pageQuery(@Param("param") JiansheUnitRequest param, @Param("limit") int limit, @Param("offset") long offset);

    List<Map<String,Object>> selectAllProject(@Param("jiansheUnitId") Long jiansheUnitId);

}
